from combat import roll
from random import randint

class Entity:
	
	def __init__(self):
		
		
		self.serial = 0
		self.name = "default"
		self.symbol = "r"
		self.color = "w"
		self.speed = 100
		self.hp = [1,7]
		self.vision = 5
		self.ac = 4
		self.alert = 2
		self.depth = 1
		self.rarity = 1
		self.exp = 5
		self.attacks = []
		self.flags = []
		self.spfreq = []
		self.spells = []
		self.desc = []
		
		#my variables
		self.role = "monster"
		self.reference = [0,0]
		self.maxhp = 0
		self.curhp = 0
		
	def instance(self):
		self.maxhp = roll(self.hp)
		self.curhp = self.maxhp
	
	def known_name(self):
		return self.name 	

class Object:
	
	def __init__(self):
		
		self.serial = 0
		self.name = "default"
		self.symbol = "/"
		self.color = "w"
		self.tval = 0
		self.sval = 0
		self.pval = 0
		self.depth = 0
		self.rarity = 1
		self.weight = 1
		self.cost = 1
		self.bac = 1
		self.bdam = 1
		self.tohit = 1
		self.todam = 1
		self.toac = 1
		self.depth2 = []
		self.charges = 0
		self.pile = 0
		self.pilesize = 0
		self.flags = []
		self.desc = []
		
		
		#my variables
		self.role = "object"
		self.reference = [0,0]
		self.id = 0 #game identified flag
		self.flavor = 0
		self.symbolword = self.symbolname(self.symbol)
		self.stack = 1 ##
		
	def symbolname( self, s ):
		if s == '?':
			return 'scroll'
		if s == '-':
			return 'wand'
		if s == '_':
			return 'staff'
		elif s == '"':
			return 'amulet'
		elif s == '!':
			return 'potion'
		elif s == '-':
			return 'wand'
		elif s == ',':
			return 'mushroom'
		elif s == '=':
			return 'ring'
		else:
			return ""
	
	def instance(self):
		if self.pile > randint(1,99):
			self.stack = roll(self.pilesize)
		if randint(1,2) == 2:  #random id for testing purposus
			self.id = 1
			
		
	def known_name(self):
		
	
		known = ""
		name = self.name
		if self.stack > 1:
			known = str(self.stack)
			name = name.replace('~','s')
		else:
			known = "A" #what about an?
			name = name.replace('~','')
			
		if self.symbol in ['?', '-', '_', '"', '!', '-', ',', '=' ]:
			known = known + " " + self.flavor[1] + " " + self.symbolname(self.symbol) + " "
			if self.id == 0:
				name = ""
			else:
				name = "of " + name
				
				## Need to consider equip vrs devices, regards to id but dont know charges
		if self.symbol in [ '\\','|', '/', '{', '}' ]: # weapons
			name = name + " (" + str(self.bdam[0]) + "d" + str(self.bdam[1]) + ") "
			if self.id == 1:
				name = name + "(+" + str(self.tohit) + ",+" + str(self.todam) + ")"
		if self.symbol in [ ']','[', ')', '(' ]: # armor
			name = name + " [" + str(self.bac)
			if self.id == 1:
				name = name + ", +" + str(self.toac)
			name = name + "]"
			
		if name[:1] == "&":
			known = known + name[1:] 
		else:
			known = known + name
		
		return known